CC=gcc
NASM=nasm
LD=ld
OBJC=objcopy
CFLAGS=-O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -fno-stack-protector -I./include -c -o
OBJS=kernel.o init.o screen.o gdt.o idt.o math.o string.o dev.o isr.o irq.o timer.o kbd.o vsprintf.o time.o mm.o shell.o
IDIR=include/
INC=$(IDIR)gdt.h $(IDIR)idt.h $(IDIR)arg.h $(IDIR)stringu.h $(IDIR)sys.h $(IDIR)video.h $(IDIR)io2.h $(IDIR)valist.h $(IDIR)mathop.h


all: kernel.elf
	make clean



kernel.elf: kernel.tmp
	$(OBJC) -O elf32-i386 kernel.tmp $@

kernel.tmp: $(OBJS) link.ld
	$(LD) -T link.ld -nostdlib -o $@ $(OBJS)

kernel.o: main.c
	$(CC) $(CFLAGS) $@ main.c

init.o: init.asm
	$(NASM) -f elf -o $@ init.asm



screen.o: lib/screen.c
	$(CC) $(CFLAGS) $@ lib/screen.c

gdt.o: lib/gdt.c
	$(CC) $(CFLAGS) $@ lib/gdt.c

idt.o: lib/idt.c
	$(CC) $(CFLAGS) $@ lib/idt.c

math.o: lib/math.c
	$(CC) $(CFLAGS) $@ lib/math.c

string.o: lib/string.c
	$(CC) $(CFLAGS) $@ lib/string.c

dev.o: lib/x86.c
	$(CC) $(CFLAGS) $@ lib/x86.c

isr.o: lib/isr.c
	$(CC) $(CFLAGS) $@ lib/isr.c
	
irq.o: lib/irq.c
	$(CC) $(CFLAGS) $@ lib/irq.c

timer.o: lib/timer.c
	$(CC) $(CFLAGS) $@ lib/timer.c

kbd.o: lib/kbd.c
	$(CC) $(CFLAGS) $@ lib/kbd.c

vsprintf.o: lib/vsprintf.c
	$(CC) $(CFLAGS) $@ lib/vsprintf.c

time.o: lib/time.c
	$(CC) $(CFLAGS) $@ lib/time.c
	
mm.o: lib/mm.c
	$(CC) $(CFLAGS) $@ lib/mm.c

shell.o: lib/os/shell.c
	$(CC) $(CFLAGS) $@ lib/os/shell.c

clean:
	rm -rf *.o *.tmp
